//
//  ZQAccount.m
//  柳州微博
//
//  Created by Apple_Lzzy40 on 16/9/30.
//  Copyright © 2016年 Apple_Lzzy40. All rights reserved.
//

#import "ZQAccount.h"

@implementation ZQAccount

+(instancetype)accountWithDict:(NSDictionary *)dict
{
    ZQAccount * account=[[self alloc] init ];
    account.access_token=dict[@"access_token"];
     account.expires_in=dict[@"expires_in"];
    account.uid=dict[@"uid"];
//    account.name=dict[@"name"];
    //保存获取令牌的日期和时间
    account.create_time=[NSDate date];
    return account;
}
/**
 *  把一个对象或模型写到沙盒中的时候调用的方法
 */
-(void)encodeWithCoder:(NSCoder *)enaCoder
{

    [enaCoder encodeObject:self.access_token forKey:@"access_token"];
    [enaCoder encodeObject:self.expires_in forKey:@"expires_in"];
    [enaCoder encodeObject:self.uid forKey:@"uid"];
    [enaCoder encodeObject:self.create_time forKey:@"create_time"];
    [enaCoder encodeObject:self.name forKey:@"name"];
}

/**
 *  从沙化当中读取对象的时候调用
 */
-(instancetype)initWithCoder:(NSCoder *)decoder
{
    if (self=[super init]) {
        self.access_token=[decoder decodeObjectForKey:@"access_token"];
        self.expires_in=[decoder decodeObjectForKey:@"expires_in"];
        self.uid=[decoder decodeObjectForKey:@"uid"];
        self.create_time=[decoder decodeObjectForKey:@"create_time"];
        self.name = [decoder decodeObjectForKey:@"name"];
    }
    return self;
}

@end
